package views

import (
	"blog/common"
	"blog/context"
	"blog/service"
	"errors"
	"strconv"
)

func (*HTMLApi) Detail(context *context.MsContext) {
	detailTemplate := common.Template.Detail
	pIdStr := context.GetPathVariable("pId")
	pId, err := strconv.Atoi(pIdStr)
	if err != nil {
		detailTemplate.WriteError(context.W, errors.New("不识别此路径"))
		return
	}
	postDetail, err := service.GetPostDetail(pId)
	if err != nil {
		detailTemplate.WriteError(context.W, errors.New("查询出错"))
		return
	}
	detailTemplate.WriteData(context.W, postDetail)
}
